package controller.user;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.swing.ListModel;
import model.Cv;
import model.InterviewFacade;
import model.Vacancy;
import model.*;

@ManagedBean(name = "smb")
@SessionScoped
public class ShownManagedBean {
    @EJB
    private InterviewFacade interviewFacade;
    @EJB
    private VacancyFacade vacancyFacade;
    private Vacancy vac = new Vacancy();
    private String value;
    private Interview inter;

    private List<Vacancy> listv;

    public List<Vacancy> getListv() {
        return listv;
    }

    public void setListv(List<Vacancy> listv) {
        this.listv = listv;
    }
    public InterviewFacade getInterviewFacade() {
        return interviewFacade;
    }

    public void setInterviewFacade(InterviewFacade interviewFacade) {
        this.interviewFacade = interviewFacade;
    }

    public Interview getInter() {
        return inter;
    }

    public void setInter(Interview inter) {
        this.inter = inter;
    }
    private Vacancy cv1 = new Vacancy();
    public Vacancy getCv1() {
        return cv1;
    }

    public void setCv1(Vacancy cv1) {
        this.cv1 = cv1;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public Vacancy getVac() {
        return vac;
    }

    public void setVac(Vacancy vac) {
        this.vac = vac;
    }

    public VacancyFacade getVacancyFacade() {
        return vacancyFacade;
    }

    public void setVacancyFacade(VacancyFacade vacancyFacade) {
        this.vacancyFacade = vacancyFacade;
    }
    
    public ShownManagedBean() {
    }
     public List<Vacancy> listvacancy(){
        return this.vacancyFacade.findAll();
    }
    public List<Interview> listinterview(){
        return this.interviewFacade.findAll();
    }
     public List<Results> vacancyList(){
 
         List<Results> list = new ArrayList<Results>();
         for(Vacancy c : this.vacancyFacade.findAll() )
         {
             int numtrue = 0;   
             for(Cv c1 : c.getCvList())
             {                               
                 for(Interview it: c1.getInterviewList() )
                     if(it.getAVStatus()==2)
                         numtrue++;
             }
             Results kq = new Results();
             kq.setnumnull(c.getNumberRequirement() -  numtrue);
             kq.setVc(c);
             if(c.getNumberRequirement() - kq.getnumnull() <= 0){
                 if(!c.getStatus().equals(2)){
                     list.add(kq);
                 }
                 
             }
         }
         return list;
     }
     
     public String link(Vacancy vac){
         this.cv1 = vac;
         this.vac = vac;
         return "recruitment";
     }
     
     public String send(){
        this.vac = this.cv1; 
         return "send";
     }
     
     
    
}
